<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <link rel="stylesheet" href="css/layerSm.css">
        <script type="text/javascript">
            
            $(document).ready(function(){
                $("#styleCategoryCd,#fitCd,#sizegroupCd,#sizeCd").select2();
            });

            //保存方法
            var saveForm={
            		
            		
                s:null,
                t:null,
                save:function(s,t){
                    $(t).attr("disabled",true);
                    this.s=s;
                    this.t=t;
                    // 表单验证
                    $("#inputForm").validate({
                        submitHandler: function() {
                            // 格式化，去除逗号
                            formUnFormat($("#inputForm"));
                            // 从表单中获取数据
                            var params = $("#inputForm").serialize();
                            // 通过调用ajax 方法调用后台方法
                            $.post("${ctx}/fabric/consumption/save",params,function(result){
                                // 提示信息
                                tipParent(result.message);
                                // 返回状态
                                if(result.statusCode==STATUSCODEOK){
                                    if(saveForm.s==1){
                                        // 重置表单
                                        $("#inputForm")[0].reset();  
                                        $("#styleCategoryCd,#fitCd,#sizegroupCd,#sizeCd").select2();
                                        $(saveForm.t).attr("disabled",false);
                                        // 刷新页面
                                        window.parent.frames[0].location.reload();
                                        addItemValue();
                                    }else{
                                        // 刷新页面
                                        window.parent.frames[0].location.reload();
                                        closeWin(); 
                                    }
                                }else{
                                    $(saveForm.t).attr("disabled",false);
                                }
                            },'json'); 
                        },
                        fail: function(element,e) {  
                            $(saveForm.t).attr("disabled",false);
                        }
                    });
                    // 提交表单
                    $("#inputForm").submit(); 
                }
            }
            
            
            //尺码
            function subStyleSize(t,id){
                var code=$(t).find("option:selected").attr("data-value");
                var param={"code":code};
                $.post("${ctx}/custom/size/styleSize",param,function(result){
                    var html="<option value=''><spring:message code='size_pleaseChoosed'/></option>";
                    $.each(result,function(i,e){
                        html+="<option value='"+e.itemCode+"-"+e.itemValue+"'>"+e.itemName+"</option>";
                    });
                    $("#"+id).html(html);
                    $("#"+id).select2();
                },'json');
                
                $('#sizeCd').select2();
            }
        </script>
    </head>
    <body>
        <!--头部-->
        <div class="myshop clearfix">
            <c:choose>
                <c:when test="${consumption.id!=null&&consumption.id!=''}">
                    <!--编辑-->
                    <p class="myshoptop fl"><spring:message code="size_editSizeCost"/></p>
                </c:when>
                <c:otherwise>
                    <!--新建尺寸尺码-->
                    <p class="myshoptop fl"><spring:message code="size_createSizeCost"/></p>
                </c:otherwise>
            </c:choose>
            <div class="fr">
                <div class="topBtnClose" onclick="closeWin()">
                    <img src="${ctxStatic}/images/btn-close.png">
                </div>
            </div>
        </div>
        <form id="inputForm" method="post">
        <c:set value="<%=ResourcesUtil.getConfig(\"size_styleCategory\")%>" var="styleCategory" />
        <c:set value="<%=ResourcesUtil.getConfig(\"size_styleFitCd\")%>" var="styleFit" />
        <c:set value="<%=ResourcesUtil.getConfig(\"size_styleSizeGroupCd\")%>" var="sizeGroup" />
        <input type="hidden" id="id" name="id" value="${consumption.id}"/>
        <input type="hidden"  name="version" value="${consumption.version}"/>
            <div class="middle myshop_middle">
                <div class="data clearfix">
                    <div class="ch fl haveToBox">
                        <!-- 款式类别 -->
                        <p class="data_id"><spring:message code="size_styleCategory"/></p>
                       <%--  <c:choose>
                            <c:when test="${consumption.id!=null&&consumption.id!=''}">
                                 <p class="rtname fl">${fns:getDictName(consumption.styleCategoryCd)}</p>
                                <input type="hidden"  name="styleCategoryCd" value="${consumption.styleCategoryCd}"/>
                            </c:when>
                            <c:otherwise> --%>
                                <select class="sex" id="styleCategoryCd" name="styleCategoryCd" data-rule-required="true" data-msg-required="<spring:message code="size_pleaseChoosedStyleCategoryCd"/>">
                                     <option value=""><spring:message code="size_pleaseChoosed"/></option>
                                      <c:forEach items="${fns:getDictList(styleCategory)}"   var="category" varStatus="status">
                                         <option <c:if test="${fn:split(consumption.styleCategoryCd,'-')[1] eq category.itemValue}">selected="selected"</c:if> value="${category.itemCode}-${category.itemValue}" > 
                                             ${category.itemName}
                                         </option>
                                     </c:forEach>
                                 </select>
                            <%-- </c:otherwise>
                        </c:choose> --%>
                        <p class="haveTo">*</p>
                    </div>
                    <div class="ch fr haveToBox">
                        <!-- 尺码组 -->
                        <p class="data_id"><spring:message code="size_sizeGroup"/></p>
                        <%-- <c:choose>
                            <c:when test="${consumption.id!=null&&consumption.id!=''}">
                                 <p class="rtname fl">${fns:getDictName(consumption.sizegroupCd)} ${fns:getDictName(consumption.sizeCd)}</p>
                                <input type="hidden" id="sizegroupCd" name="sizegroupCd" value="${consumption.sizegroupCd}"/>
                                <input type="hidden" id="sizeCd" name="sizeCd" value="${consumption.sizeCd}"/>
                            </c:when>
                            <c:otherwise> --%>
                                <select class="sex form-control-2" style="width:170px;;display:block;float:left;" id="sizegroupCd" name="sizegroupCd" onchange="subStyleSize(this,'sizeCd')" data-rule-required="true" data-msg-required="<spring:message code="size_pleaseChoosedStyleSizeGroupCd"/>" >
                                     <option value=""><spring:message code="size_pleaseChoosed"/></option>
                                      <c:forEach items="${fns:getDictList(sizeGroup)}"   var="group" >
                                         <option data-value="${group.itemValue}"  <c:if test="${fn:split(consumption.sizegroupCd,'-')[1] eq group.itemValue}">selected="selected"</c:if> value="${group.itemCode}-${group.itemValue}" > 
                                             ${group.itemName}
                                         </option>
                                     </c:forEach>
                                 </select>
                                <select class=" sex form-control-2 fr" style="width:170px;display:block;float:right;" id="sizeCd" name="sizeCd"  data-rule-required="true" data-msg-required="<spring:message code="size_pleaseChoosedStyleSizeCd"/>">
                                    <option value=""><spring:message code="size_pleaseChoosed"/></option>
                                    <c:forEach items="${fns:getDictList(fn:split(consumption.sizegroupCd, '-')[1])}" var="styleSize">
                                        <option 
                                            <c:if test="${fn:split(consumption.sizeCd, '-')[1] eq styleSize.itemValue}">selected="selected"</c:if>  value="${styleSize.itemCode}-${styleSize.itemValue}">
                                            ${styleSize.itemName}
                                        </option>
                                    </c:forEach>
                                </select>
                            <%-- </c:otherwise>
                        </c:choose> --%>
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl haveToBox">
                        <!-- 版型 -->
                        <p class="data_id"><spring:message code="size_styleFit"/></p>
                        <%-- <c:choose>
                            <c:when test="${consumption.id!=null&&consumption.id!=''}">
                                 <p class="rtname fl">${fns:getDictName(consumption.fitCd)}</p>
                                <input type="hidden" id="fitCd" name="fitCd" value="${consumption.fitCd}"/>
                            </c:when>
                            <c:otherwise> --%>
                                <select class="sex" id="fitCd" name="fitCd" data-rule-required="true" data-msg-required="<spring:message code="size_pleaseChoosedStyleFitCd"/>" >
                                     <option value=""><spring:message code="size_pleaseChoosed"/></option>
                                      <c:forEach items="${fns:getDictList(styleFit)}"   var="fit" varStatus="status">
                                         <option <c:if test="${fn:split(consumption.fitCd,'-')[1] eq fit.itemValue}">selected="selected"</c:if> value="${fit.itemCode}-${fit.itemValue}" > 
                                             ${fit.itemName}
                                         </option>
                                     </c:forEach>
                                 </select>
                            <%-- </c:otherwise>
                        </c:choose> --%>
                        <p class="haveTo">*</p>
                    </div>
                    <div class="ch fr">
                        <!-- 状态 -->
                        <p class="data_id"><spring:message code="size_state"/></p>
                        <%-- <c:choose>
                            <c:when test="${consumption.id!=null&&consumption.id!=''}">
                                 <p class="rtname fl">
                                    <c:choose>
                                        <c:when test="${consumption.enableFlag eq 1}"><spring:message code="size_enable"/></c:when>
                                    </c:choose>
                                    <c:choose>
                                        <c:when test="${consumption.enableFlag eq 0}"><spring:message code="size_disable"/></c:when>
                                    </c:choose>
                                </p>
                                <input type="hidden"  name="enableFlag" value="${consumption.enableFlag}"/>
                            </c:when>
                            <c:otherwise> --%>
                                <label class="lbst">
                                    <input type="radio" name="enableFlag" checked='checked' value="1" <c:if test="${consumption.enableFlag eq 1}">checked="checked"</c:if> class="rast"/><spring:message code="size_enable"/>
                                </label>
                                <label class="lbst">
                                    <input type="radio" name="enableFlag" value="0" <c:if test="${consumption.enableFlag eq 0}">checked="checked"</c:if> class="rast" /><spring:message code="size_disable"/>
                                </label>
                            <%-- </c:otherwise>
                        </c:choose> --%>
                    </div>
                </div>
                <div class="data clearfix ">
                    <div class="ch fl haveToBox">
                    <!--面料单耗-->
                        <p class="data_id"><spring:message code="size_sizeUnitCost"/></p>
                        <input onfocus="unFormat(this)" onblur="formatMoney(this,3)" value="<fmt:formatNumber value="${consumption.sizeUnitCost}" pattern="#,#0.000#"/>" name="sizeUnitCost" maxlength="20"  data-rule-integerDecimalmax="7.3" data-msg-integerDecimalmax="<spring:message code="size_maxPrompt"/>"  class="form-control" data-rule-required="true" data-msg-required="<spring:message code="size_maxPrompt"/>" type="tel">
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="clearfix">
                    <div class="ch fl haveToBox">
                        <!-- 备注-->
                        <p class="data_id"><spring:message code="size_remarks"/></p>
                        <div class="data_ip fl">
                            <!-- 请输入备注内容 -->
                            <textarea name="remarks" class="dsp" maxlength="100">${consumption.remarks}</textarea>
                        </div>
                    </div>
                </div>
                <div class="twobtn" style="margin-top:269px;">
                    <div class="onebtn clearfix">
                        <shiro:hasPermission name="fabric:consumption:edit">
                        <!--尺码保存-->
                        <button type="button" class="btn save fl" style="margin:0 auto;" onclick="saveForm.save(0,this)"><spring:message code="size_save"/></button>
                        <c:if test="${empty consumption.id}">
                        <!--尺码保存并继续-->
                        <button type="button" class="btn gon fr" onclick="saveForm.save(1,this)"><spring:message code="size_saveAndcontinue"/></button>
                        </c:if>
                        </shiro:hasPermission>
                    </div>
                </div>
            </div>
        </form>
        <script>
            var windowH = window.innerHeight
                    ||document.documentElement.clientHeight
                    ||document.body.clientHeight
            $('.middle').css('height',windowH - 40);
            var theadW = $('.tabScroll thead').width();
            var theadTh = $('.tabScroll thead tr th').length;
            $('.tabScroll thead tr th').width(theadW/theadTh);
            $('.tabScroll tbody tr:first-child td').each(function(){
                var indexNum = $(this).index();
                var tdWidth = $('.tabScroll tbody tr:first-child td').eq(indexNum).css('width');
                $('.tabScroll thead tr th').eq(indexNum).width(tdWidth);
            });
           
        </script>
    </body>
</html>